package com.ruoyi.web.controller.business;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.TOperationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/system/operation1")
public class TOperation1Controller {
    @Autowired
    TOperationService tOperationService;

    private String prefix = "system/operation1";

    @RequiresPermissions("system:operation1:view")
    @GetMapping()
    public String operation() {
        return prefix + "/operation1";
    }

    /**
     * 医生或药房查询销售额与角色
     */
    @RequiresPermissions("system:operation:getSalesAndRoles")
    @PostMapping("/getSalesAndRoles")
    @ResponseBody
    public AjaxResult getSalesAndRoles(TSalesAndRoles tSalesAndRoles) {
        Tuserid tuserid = new Tuserid();
        tuserid.setUserid(tSalesAndRoles.getUserId());
        TSysUser userDepartment = tOperationService.getUserDepartment(tuserid);
        //判断id
        int deptId = userDepartment.getDept_id();
        Tres2 res = new Tres2();
        res.setDeptId(deptId);
        res.setUserName(userDepartment.getUser_name());

        if (deptId == 110 || deptId == 112) {
            Tres tres = tOperationService.getSalesAndRoles(tSalesAndRoles);
            res.setAmount(tres.getAmount());
            return AjaxResult.success(res);
        } else if (deptId == 111) {
            Tres tres1 = tOperationService.getNurseSalesData(tSalesAndRoles);
            Tres tres2 = tOperationService.getNurseZhusheData(tSalesAndRoles);
            res.setAmount(tres1.getAmount());
            res.setZsrs((int) tres2.getAmount());
        }
        return AjaxResult.success(res);
    }
}
